﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

namespace HelloASPX
{
    public partial class FindPassWord : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void username_TextChanged(object sender, EventArgs e)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(Server.MapPath("~/App_Data/user.xml"));
            XmlNodeList usernodes = doc.SelectNodes("//user[username='" + username.Text + "']");
            if (usernodes.Count > 0)
            {
                usernameLabel.Text = "";
                passwordQuestion.Text = usernodes[0].SelectSingleNode("passwordQuestion").InnerText;
            }
            else
            {
                usernameLabel.Text = "该用户名不存在！仔细看看是不是填错了！";
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (answer.Text == "" || username.Text=="")
            {
                return;
            }
            XmlDocument doc = new XmlDocument();
            doc.Load(Server.MapPath("~/App_Data/user.xml"));
            XmlNode usernode = doc.SelectSingleNode("/users/user[username='" + username.Text + "']");
            if (usernode == null)
            {
                return;
            }
            if (usernode.SelectSingleNode("answer").InnerText == answer.Text)
            {
                Response.Write("<script>alert('记牢啦，您的密码为：" + usernode.SelectSingleNode("mima").InnerText + "');location='Login.aspx'</script>");
            }
            else
            {
                Response.Write("<script>alert('看来是您回答错问题了！');</script>");
            }
        }
    }
}